/*
 * @(#)MessagesTag.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework.taglib.html;


import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts.util.ResponseUtils;

import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;

/**
  SummarizeContentTag.java

     @author          Vera Wang
    @company         DCIVision Limited
    @creation date   20/5/2003
    @version         $Revision: 1.4 $
*/

public class SummarizeContentTag extends TagSupport {

  public static final String REVISION = "$Revision: 1.4 $";

  
  public static final int DEFAULT_LENGTH = (SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.CALENDAR_MAX_WORDS_OF_TITLE).intValue());
  protected String key = null;
  protected int limitLength = DEFAULT_LENGTH;
 
  
  public String getKey() {
    return (this.key);
  }

  public void setKey(String key) {
    this.key = key;
  }

  public int getLimitLength() {
    return (this.limitLength);
  }

  public void setLimitLength(int limitLength) {
 		this.limitLength = limitLength;	
  }

  public int doStartTag() throws JspException {
    if ((this.key == null)) {
        return (EVAL_BODY_INCLUDE);
    }    
    if (this.key.length() < this.limitLength)
      ResponseUtils.write(pageContext, this.key);
    else
      ResponseUtils.write(pageContext, this.key.substring(0,this.limitLength)+"..." );
    return (EVAL_BODY_INCLUDE);
  }

  public void release() {
    super.release();
    key = null;
    limitLength = 1;
  }

}
